import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-06
 * Time: 21:53
 */
class Student1 {
    String name;
    int age;
    double score;
    public Student1(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
    @Override
    public String toString() {
        return "Student{" +
                "姓名='" + name + '\'' +
                ", 年龄=" + age +
                ", 成绩=" + score +
                '}';
    }
}
//比较器 根据姓名比较
class NameComparator implements Comparator<Student1> {
    @Override
    public int compare(Student1 o1, Student1 o2) {
        return o1.name.compareTo(o2.name);
    }
}
//根据年龄比较
class AgeComparator implements Comparator<Student1> {
    @Override
    public int compare(Student1 o1, Student1 o2) {
        return o1.age - o2.age;
    }
}
//通过成绩比较
class ScoreComparator implements Comparator<Student1> {
    @Override
    public int compare(Student1 o1, Student1 o2) {
        return (int) (o1.score-o2.score);
    }
}
public class Test02 {
    public static void main(String[] args) {
        Student1[] student = {
                new Student1("张三",18,60.5),
                new Student1("李四",25,78.5),
                new Student1("王五",10,45.25),
        };
//        //通过姓名比较
//        NameComparator nameComparator = new  NameComparator();
//        Arrays.sort(student,nameComparator);
//        //通过年龄比较
//         AgeComparator ageComparator = new AgeComparator();
//         Arrays.sort(student,ageComparator);
        //通过成绩比较
        ScoreComparator ScoreComparator = new ScoreComparator();
        Arrays.sort(student,ScoreComparator);
        System.out.println(Arrays.toString(student));
    }
}
